package com.granada.service.ping;


import com.granada.behaviour.base.PermissionBehavior;
import com.granada.entity.Ao;
import com.granada.behaviour.base.RoleBehavior;
import com.granada.behaviour.base.UserBehavior;
import com.granada.behaviour.base.UserRoleBehavior;
import com.granada.constants.Constant;
import com.granada.model.common.User;
import com.granada.service.base.UserService;
import com.granada.utils.ServiceBeanUtils;
import com.granada.vo.resp.UserOwnRoleRespVO;

import java.util.List;
import java.util.concurrent.TimeUnit;

public class UserWithPingService extends UserService {


    public UserWithPingService(User userModel, UserBehavior userBehavior, PermissionBehavior permissionBehavior, RoleBehavior roleBehavior, UserRoleBehavior userRoleBehavior, Ao ao) {
        super(userModel, userBehavior, permissionBehavior, roleBehavior, userRoleBehavior, ao);
    }

    @Override
    public UserOwnRoleRespVO getUserOwnRole(Long userId) throws Exception {
        return this.userBehavior.getUserOwnRole(userId);
    }

    @Override
    public void resetAccountAndPassword(Long id) throws Exception {

    }

    @Override
    public void setUserOwnRole(Long userId, List<Long> roleIds) throws Exception {
        userRoleBehavior.addBatch(roleIds,userId);
        ServiceBeanUtils.getRedisService().set(Constant.JWT_REFRESH_KEY+userId,userId,ServiceBeanUtils.getTokenSettings().getAccessTokenExpireTime().toMillis(), TimeUnit.MILLISECONDS);
        //清空权鉴缓存
        ServiceBeanUtils.getRedisService().delete(Constant.IDENTIFY_CACHE_KEY+userId);
    }
}
